//
//  UIviewControllerExtension.swift
//  WS-Designated_Driver
//
//  Created by Yuri on 2020/7/10.
//  Copyright © 2020 WSJC. All rights reserved.
//

import UIKit

extension UIViewController {
    
    /// 当前显示的控制器
    class func current(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
        if let nav = base as? UINavigationController {
            return current(base: nav.visibleViewController)
        }
        if let tab = base as? UITabBarController {
            return current(base: tab.selectedViewController)
        }
        if let presented = base?.presentedViewController {
            return current(base: presented)
        }
        return base
    }
}
